package com.aco.party.model.vo.common;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by whz on 2014/11/1.
 */
@Data
public class DataGridEntry {
    // 页数
    private Integer page;
    // 每月显示数
    private Integer rows;
    //排序方式
    private String order;
    //排序字段
    private String sort;

    private Integer offset;
    private Integer limit;
    private String orderBy;

    public void webParamConvert() {
        if (rows != null && page != null) {
            offset = rows * (page - 1);
            limit = rows;
        } else {
            offset = null;
            limit = null;
        }
        if (StringUtils.isNotBlank(sort)) {
            orderBy += sort;
            if (StringUtils.isNotBlank(order)) {
                orderBy += " " + order;
            }
        }
    }

	public static DataGridEntry getDefault() {
		DataGridEntry dge = new DataGridEntry();
		dge.setPage(1);
		dge.setRows(50);
		dge.webParamConvert();
		return dge;
	}
}
